////////////////////////////////////////////////////////////////////////////////
//
//  This program is free software; you can redistribute it and/or modify 
//  it under the terms of the GNU Lesser General Public License as published 
//  by the Free Software Foundation; either version 3 of the License, or (at 
//  your option) any later version.
//
//  This program is distributed in the hope that it will be useful, but 
//  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
//  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
//  License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License 
//  along with this program; if not, see <http://www.gnu.org/copyleft/lesser.html>.
//
////////////////////////////////////////////////////////////////////////////////

package merapi.gps.handlers;


import merapi.gps.GPSProxy;
import merapi.gps.messages.GPSMessage;
import merapi.gps.model.GPSConfig;
import merapi.handlers.MessageHandler;
import merapi.messages.IMessage;

/**
 *  Handles Messages types of the GPSMessage types
 *  
 *  @author Adam Flater - adamflater.net
 */
public class GPSMessageHandler extends MessageHandler 
{
	//--------------------------------------------------------------------------
	//
	//  Constructors
	//
	//--------------------------------------------------------------------------
	
	/**
	 *  The default constructor
	 */
	public GPSMessageHandler()
	{
		super();
		
		addMessageType( GPSMessage.CONFIG );
		addMessageType( GPSMessage.START );
		addMessageType( GPSMessage.STOP );
	}


	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 *  Handles the registered messages
	 */
	public void handleMessage( IMessage message ) 
	{
		if ( message.getType().equals( GPSMessage.CONFIG ) )
		{
			GPSProxy.setConfiguration( (GPSConfig)message.getData() );
		}
		else if ( message.getType().equals( GPSMessage.START ) )
		{
			GPSProxy.start();
		}
		else if ( message.getType().equals( GPSMessage.STOP ) )
		{
			GPSProxy.stop();
		}
	}

}
